//相同时间的一起建图，建了多组图，这种建图方法值得学习
class Solution {
public:
    vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {
        vector<unordered_map<int,vector<int>>> arrg;
        vector<bool> vis(n,false);
        sort(meetings.begin(),meetings.end(),[](const vector<int>& v1,const vector<int>& v2)
        {
            return v1[2] < v2[2];
        });
        for(int i = 0;i < meetings.size();i++)
        {
            if(i == 0 || meetings[i][2] > meetings[i-1][2])//到下一组了
            {
                arrg.push_back({});
            }
            auto& tmp = arrg.back();//拿到当前组的哈希表
            int u = meetings[i][0];
            int v = meetings[i][1];
            tmp[u].push_back(v);
            tmp[v].push_back(u);
        }

        unordered_map<int,vector<int>> curmap;

        auto dfs = [&](this auto&& dfs,int cur)->void
        {
            vis[cur] = true;
            for(auto& next : curmap[cur])
            {
                if(vis[next]) continue;
                dfs(next);
            }
        };

        vis[0] = vis[firstPerson] = true;
        for(int i = 0;i < arrg.size();i++)
        {
            curmap = arrg[i];
            for(auto& e : curmap)
            {
                if(vis[e.first]) dfs(e.first);//知晓的专家开始传播
            }
        }

        vector<int> ans;
        for(int i = 0;i < n;i++)
        {
            if(vis[i]) ans.push_back(i);
        }
        return ans;
    }
};